package com.ruoyi.wm.controller;

import java.util.Collection;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wm.domain.WmMedicines;
import com.ruoyi.wm.service.IWmMedicinesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药品列表Controller
 * 
 * @author hpf
 * @date 2021-12-02
 */
@Controller
@RequestMapping("/wm/wm_medicines")
public class WmMedicinesController extends BaseController
{
    private String prefix = "wm/wm_medicines";

    @Autowired
    private IWmMedicinesService wmMedicinesService;

    @RequiresPermissions("wm:wm_medicines:view")
    @GetMapping()
    public String wm_medicines()
    {
        return prefix + "/wm_medicines";
    }

    /**
     * 查询药品列表列表
     */
    @RequiresPermissions("wm:wm_medicines:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WmMedicines wmMedicines)
    {
        startPage();
        List<WmMedicines> list = wmMedicinesService.selectWmMedicinesList(wmMedicines);
        return getDataTable(list);
    }

    /**
     * 导出药品列表列表
     */
    @RequiresPermissions("wm:wm_medicines:export")
    @Log(title = "药品列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WmMedicines wmMedicines)
    {
        List<WmMedicines> list = wmMedicinesService.selectWmMedicinesList(wmMedicines);
        ExcelUtil<WmMedicines> util = new ExcelUtil<WmMedicines>(WmMedicines.class);
        return util.exportExcel(list, "wm_medicines");
    }

    /**
     * 新增药品列表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存药品列表
     */
    @RequiresPermissions("wm:wm_medicines:add")
    @Log(title = "药品列表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WmMedicines wmMedicines)
    {
        return toAjax(wmMedicinesService.insertWmMedicines(wmMedicines));
    }

    /**
     * 修改药品列表
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WmMedicines wmMedicines = wmMedicinesService.selectWmMedicinesById(id);
        mmap.put("wmMedicines", wmMedicines);
        return prefix + "/edit";
    }

    /**
     * 修改保存药品列表
     */
    @RequiresPermissions("wm:wm_medicines:edit")
    @Log(title = "药品列表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WmMedicines wmMedicines)
    {
        return toAjax(wmMedicinesService.updateWmMedicines(wmMedicines));
    }

    /**
     * 删除药品列表
     */
    @RequiresPermissions("wm:wm_medicines:remove")
    @Log(title = "药品列表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wmMedicinesService.deleteWmMedicinesByIds(ids));
    }
}
